package com.dap.dao;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.dap.cache.common.RedisAnnotationCache;
import com.dap.dao.model.BaseBeanQuery;
import com.dap.dao.model.Page;

public interface DaoSupport {
    String POSTFIX_COUNT = ".count";
    String POSTFIX_SELECTONE = ".selectOne";
    String POSTFIX_INSERT = ".insert";
    String POSTFIX_BATCH_INSERT = ".batchInsert";
    String POSTFIX_UPDATE = ".update";
    String POSTFIX_UPDATE_BY_ENTITY = ".updateByEntity";
    String POSTFIX_DELETE = ".delete";
    String POSTFIX_BATCH_IDELETE = ".batchDelete";
    String POSTFIX_SELECTLIST = ".selectList";

    String BATCH_INSERT_PARAMETER_NAME = "list";
    String BATCH_DELETE_PARAMETER_NAME = "list";


    @Deprecated
    Integer count(String statementPostfix, Object parameter);
    Integer count(Object parameter);
    Integer count(Class<?> namespaceClass, Object parameter);
    Integer count(Class<?> namespaceClass, String methodName, Object parameter);
    Integer countForUpdate(Object parameter);
    Integer countForUpdate(Class<?> namespaceClass, Object parameter);
    Integer countForUpdate(Class<?> namespaceClass, String methodName, Object parameter);


    <T extends BasePo> T selectOne(T parameter);
    <T extends BasePo> T selectOne(Class<T> namespaceClass, T parameter);
    @Deprecated
    <T> T selectOne(String statementPostfix, Object parameter);
    <T> T selectOne(Class<?> namespaceClass, String methodName, Object parameter);
    <ResultType extends BasePo> ResultType selectOne(Class<?> namespaceClass, String methodName, Map<String, Object> parameter);
    <T extends BasePo> T selectForUpdate(T parameter);
    <T extends BasePo> T selectForUpdate(Class<T> namespaceClass, T parameter);
    @Deprecated
    <T> T selectForUpdate(String statementPostfix, Object parameter);
    <T> T selectForUpdate(Class<?> namespaceClass, String methodName, Object parameter);


    <T extends BasePo> int insert(T parameter);
    <T extends BasePo> int insert(Class<T> namespaceClass, T parameter);
    <T extends BasePo> int insert(String methodName, T entity);
    <T extends BasePo> int insert(Class<?> namespaceClass, String methodName, T entity);
    int insert(Class<?> namespaceClass, String methodName, Map<String, Object> parameter);
    <T extends BasePo> int insert(Collection<T> collection);
    <T extends BasePo> int insert(String methodName, Collection<T> collection);
    <T extends BasePo> int insert(Class<T> namespaceClass, Collection<T> collection);
    <T extends BasePo> int insert(Class<T> namespaceClass, String methodName, Collection<T> collection);

    @Deprecated
    <T extends BasePo> int update(T parameter);
    <T extends BasePo> int updateById(T parameter);
    <T extends BasePo> int updateById(Class<T> namespaceClass, T parameter);
    @Deprecated
    <T extends BasePo> int update(T setParameter, T whereParameter);
    <T extends BasePo> int updateByWhereSet(Class<T> namespaceClass, T setParameter, T whereParameter);
    @Deprecated
    <T extends BasePo> int update(String statementPostfix, T setParameter, T whereParameter);
    <T extends BasePo> int update(Class<?> namespaceClass, String methodName, T setParameter, T whereParameter);
    @Deprecated
    <T extends BasePo> int update(String statementPostfix, T parameter);
    <T extends BasePo> int update(Class<?> namespaceClass, String methodName, T parameter);
    /**
     * 更新对象
     * 
     * @param statementPostfix 自定义sql ID
     * @param parameter
     * @return 更新的记录数 @
     */
    @Deprecated
    int update(String statementPostfix, Map<String, Object> parameter);
    int update(Class<?> namespaceClass, String methodName, Map<String, Object> parameter);


    <T extends BasePo> int delete(T parameter);
    <T extends BasePo> int delete(Class<T> namespaceClass, T parameter);
    @Deprecated
    int delete(String statementPostfix, Object parameter);
    int delete(Class<?> namespaceClass, String methodName, Object parameter);
    <IdType> int batchDelete(Class<?> namespaceClass, Collection<IdType> ids);


    /**
     * 查询一个列表， 不分页
     */
    <T extends BasePo> List<T> selectList(T entity);
    <T extends BasePo> List<T> selectList(Class<T> namespaceClass, T entity);
    @Deprecated
    <T> List<T> selectList(String statementPostfix, Object parameter);
    <T> List<T> selectList(Class<?> namespaceClass, String methodName, Object parameter);
    <T extends BasePo> List<T> selectListForUpdate(T entity);
    <T extends BasePo> List<T> selectListForUpdate(Class<T> namespaceClass, T entity);
    <T> List<T> selectListForUpdate(Class<?> namespaceClass, String methodName, Object parameter);

    /**
     * 分页查询 ,pageIndex和pageSize构建成RowBounds， 针对RowBounds做了拦截重写sql
     */
    <T extends BasePo> List<T> selectList(T entity, Integer pageIndex, Integer pageSize);
    <T extends BasePo> List<T> selectList(Class<T> namespaceClass, T entity, Integer pageIndex, Integer pageSize);
    @Deprecated
    <T> List<T> selectList(String statementPostfix, Object parameter, Integer pageIndex, Integer pageSize);
    <T> List<T> selectList(Class<?> namespaceClass, String methodName, Object parameter, Integer pageIndex, Integer pageSize);

    /**
     * 分页查询 ,pageIndex和pageSize构建成RowBounds， 针对RowBounds做了拦截重写sql
     */
    <T extends BasePo> Page<T> selectQueryResult(T entity, Integer pageIndex, Integer pageSize);
    <T extends BasePo> Page<T> selectQueryResult(Class<T> namespaceClass, T entity, Integer pageIndex, Integer pageSize);
    @Deprecated
    <T> Page<T> selectQueryResult(String statementPostfix, Object parameter, Integer pageIndex, Integer pageSize);
    <T> Page<T> selectQueryResult(Class<?> namespaceClass, String methodName, Object parameter, Integer pageIndex, Integer pageSize);

    <T> List<T> queryListByBean(Class<?> namespaceClass, Object parameter);
    <T, P extends BaseBeanQuery> Page<T> queryPageByBean(Class<?> namespaceClass, P parameter);
    Integer countByBean(Class<?> namespaceClass, Object parameter);
    int deleteByBean(Class<?> namespaceClass, Object parameter);



    /**
     * 下面的所有方法走缓存
     */
    @Deprecated
    @RedisAnnotationCache
    <T extends BasePo> List<T> selectListCached(final String keyPrefix, final Object key, final Integer expiration, T entity);
}
